package com.atguigu.admin.config;

import com.atguigu.admin.intercepter.LoginIntercepter;
import com.atguigu.admin.intercepter.RequestCountIntercepter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 定制化springMVC的功能实现WebMvcConfigurer接口
 *
 */
@Configuration
public class AdminWebConfig implements WebMvcConfigurer {

//    @Autowired
//    RequestCountIntercepter requestCountIntercepter;


    //配置拦截器

    /**
     *   /**:把静态资源也会被拦截
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginIntercepter())
                .addPathPatterns("/**")
                //放行的请求"/css/**","/font/**","/images/**","/js/**"
                //方式二:使用静态资源访问前缀
                .excludePathPatterns("/","/login","/css/**","/font/**","/images/**","/js/**,/admin");


//        registry.addInterceptor(requestCountIntercepter)
//                .addPathPatterns("/**")
//                .excludePathPatterns("/","/login","/css/**","/font/**","/images/**","/js/**");
    }


}
